﻿using UnityEngine;

[RequireComponent(typeof(Animator))]
public class NAnimatorController : MonoBehaviour
{
    private Animator m_Animator;
    private Animator AnimatorComponent
    {
        get
        {
            if (!m_Animator)
            {
                m_Animator = m_Animator = transform.GetComponent<Animator>();
            }
            return m_Animator;
        }
    }

    public void PlayAnimation(string animationName, bool isStop = false, float speed = 1)
    {
        if (isStop)
        {
            Stop();
        }
        AnimatorComponent.speed = speed;
        AnimatorComponent.Play(animationName);
        OnPlayAnimation(animationName);
    }

    protected virtual void OnPlayAnimation(string animationName)
    {
        
    }
    
    public void Stop()
    {
        AnimatorComponent.StopPlayback();
    }
}